home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / d3_zgraph.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  3.3 KB  |  147 lines

  1. /*****************************************************************************
  2.   FILE           : d3_zgraph.c
  3.   SHORTNAME      : zgraph.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : z-buffer for the hidden line detection
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Ralf Huebner
  10.   DATE           : 1.12.1991
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)d3_zgraph.c    1.11 3/2/94
  14.   SCCS VERSION   : 1.11
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <values.h>
  25. #include <malloc.h>
  26. #include <X11/Xlib.h>
  27. #include <X11/Intrinsic.h>
  28.  
  29. #include "glob_typ.h"
  30.  
  31. #include "ui.h"
  32. #include "d3_global.h"
  33. #include "d3_graph.h"
  34.  
  35. #include "d3_zgraph.ph"
  36.  
  37.  
  38. /*****************************************************************************
  39.   FUNCTION : d3_initZbuffer
  40.  
  41.   PURPOSE  : init and clear z-buffer
  42.   RETURNS  : int
  43.   NOTES    :
  44.  
  45.   UPDATE   :
  46. ******************************************************************************/
  47.  
  48. int d3_initZbuffer (void)
  49.  
  50. {
  51.    d3_getRootSizes ((unsigned int *) &zbuffer_xsize, (unsigned int *) &zbuffer_ysize);
  52.  
  53.    if (!zbuffer_isInit) {
  54.         zbuffer = (float *) malloc (zbuffer_xsize * zbuffer_ysize * sizeof (float));
  55.         if (zbuffer == NULL) {
  56.             fprintf (stderr, "Error allocating zbuffer");
  57.             return (FALSE);
  58.     }
  59.         zbuffer_isInit = TRUE;
  60.     }
  61.     d3_clearZbuffer ();
  62.     return (TRUE);
  63. }
  64.  
  65.  
  66. /*****************************************************************************
  67.   FUNCTION : d3_clearZbuffer
  68.  
  69.   PURPOSE  : clear z-buffer
  70.   RETURNS  : void
  71.   NOTES    :
  72.  
  73.   UPDATE   :
  74. ******************************************************************************/
  75.  
  76. void d3_clearZbuffer (void)
  77.  
  78. {
  79.   float  *zbuf_ptr, *limit;
  80.  
  81.   limit = zbuffer + zbuffer_ysize * zbuffer_ysize;
  82.   for (zbuf_ptr = zbuffer; zbuf_ptr < limit; zbuf_ptr++)
  83.     *zbuf_ptr = MAXFLOAT;
  84. }
  85.  
  86.  
  87. /*****************************************************************************
  88.   FUNCTION : d3_readZbuffer
  89.  
  90.   PURPOSE  : read a value out of the z-buffer
  91.   RETURNS  : void
  92.   NOTES    :
  93.  
  94.   UPDATE   :
  95. ******************************************************************************/
  96.  
  97. void d3_readZbuffer (int x, int y, float *z)
  98.  
  99. {
  100.     if ((x >= 0) && (x < zbuffer_xsize) && (y >= 0) && (y < zbuffer_ysize))
  101.          *z = *(zbuffer + y*zbuffer_ysize + x);
  102.     else {
  103.          *z = 0.0;
  104.     }
  105. }
  106.  
  107.  
  108. /*****************************************************************************
  109.   FUNCTION : d3_writeZbuffer
  110.  
  111.   PURPOSE  : write a value into the z-buffer
  112.   RETURNS  : void
  113.   NOTES    :
  114.  
  115.   UPDATE   :
  116. ******************************************************************************/
  117.  
  118. void d3_writeZbuffer (int x, int y, float z)
  119.  
  120. {
  121.     if ((x >= 0) && (x < zbuffer_xsize) && (y >= 0) && (y < zbuffer_ysize))
  122.         *(zbuffer + y*zbuffer_ysize + x) = z;
  123. }
  124.  
  125.  
  126. /*****************************************************************************
  127.   FUNCTION : d3_freeZbuffer
  128.  
  129.   PURPOSE  : free the memory if the z-buffer is not longer used
  130.   RETURNS  : void
  131.   NOTES    :
  132.  
  133.   UPDATE   :
  134. ******************************************************************************/
  135.  
  136. void d3_freeZbuffer (void)
  137.  
  138. {
  139.     if (zbuffer_isInit) {
  140.         free (zbuffer);
  141.         zbuffer_isInit = FALSE;
  142.     }
  143. }
  144.  
  145. /* end of file */
  146. /* lines: 163 */
  147.